package com.base.cn.platform.os.controller.op.affiche;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.service.manage.op.affiche.OpAfficheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 消息管理
 * @author zsw
 * @since 2018/5/4
 */
@Controller
@RequestMapping("/admin/op/affiche")
public class AdminOpAfficheController extends AdminBaseController {

    @Autowired
    private OpAfficheService opAfficheService;

    /**
     * 搜索消息列表
     * @param model
     * @return 消息列表
     */
    @RequestMapping("/queryAfficheList")
    public String queryAfficheList(Model model){
        return resultPage("/op/affiche/affiche-list");
    }

    /**
     * ajax搜索消息列表
     * @param model
     * @param currentPage 当前页码
     * @param params 查询条件
     * @return 消息详情列表
     */
    @RequestMapping("/queryAjaxAfficheList")
    public String queryAjaxAfficheList(Model model,
                                       @RequestParam(value = "currentPage", required = false,defaultValue = "1")int currentPage,
                                       @RequestBody Map<String, Object> params){
        Map<String, Object> dataMap = opAfficheService.queryAjaxAfficheList(currentPage, params,true,true,true);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/op/affiche/affiche-ajax-list");
    }

    /**
     * 跳转发布消息页面
     * @param model
     * @return 发布消息页面
     */
    @RequestMapping("/toSaveUpdateAffiche")
    public String toSaveUpdateAffiche(Model model){
        return resultPage("/op/affiche/save-update-affiche");
    }

    /**
     * 跳转查看消息详情页面
     * @param afficheId 消息id
     * @return 消息详情页面
     */
    @RequestMapping("/toShowAffiche")
    public String toShowAffiche(Model model,BigDecimal afficheId){
        Map<String, Object> affiche = opAfficheService.findAfficheById(afficheId,true,true,true);
        model.addAttribute("affiche",affiche);
        return resultPage("/op/affiche/affiche-info");
    }

    /**
     * 发布消息
     * @param affiche 消息
     * @return
     */
    @RequestMapping("/saveUpdateAffiche")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "发布消息")
    public Map<String,Object> saveUpdateAffiche(HttpServletRequest request,
                                                @RequestBody Map<String,Object> affiche){
        BigDecimal createUserId = loginUtil.getLoginUserId(request);
        affiche.put("createUserId",createUserId);
        return opAfficheService.saveUpdateAffiche(affiche);
    }

    /**
     * 根据消息id批量操作 修改，恢复 , 删除
     * @param afficheIds 消息id串
     * @param status 0正常 1冻结 2删除
     * @return
     */
    @RequestMapping("/updateAfficheStatusByIds")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "修改消息状态")
    public Map<String,Object> updateAfficheStatusByIds(@RequestParam("afficheIds")String afficheIds,
                                                       @RequestParam("status")Integer status){
        return opAfficheService.updateAfficheStatusByIds(afficheIds,status);
    }

}
